from sqlalchemy import Column, Integer, String, Numeric, DateTime, ForeignKey
from sqlalchemy.sql import func
from ..core.database import Base

class UserOrder(Base):
    __tablename__ = "user_orders"
    
    id = Column(Integer, primary_key=True, index=True)
    user_id = Column(Integer, ForeignKey("users.id"), nullable=False)
    group_buy_order_id = Column(Integer, ForeignKey("group_buy_orders.id"), nullable=False)
    product_id = Column(Integer, ForeignKey("products.id"), nullable=False)
    order_no = Column(String(50), unique=True, nullable=False)
    shares = Column(Integer, nullable=False)
    total_amount = Column(Numeric(10, 2), nullable=False)
    payment_status = Column(Integer, default=0)  # 0:待支付 1:已支付 2:已退款
    payment_time = Column(DateTime(timezone=True))
    refund_time = Column(DateTime(timezone=True))
    created_at = Column(DateTime(timezone=True), server_default=func.now())
    updated_at = Column(DateTime(timezone=True), server_default=func.now(), onupdate=func.now()) 